package cn.edu.neusoft.wuguangsheng.market.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.market.activity.CartFoodsActivity;
import cn.edu.neusoft.wuguangsheng.market.bean.ShowCartBean;

/**
 * Created by little on 2018/4/23.
 */

public class CartTiaoMuAdapter extends BaseAdapter<ShowCartBean> {
    public CartTiaoMuAdapter(Context context, List<ShowCartBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(context)
                .inflate(layoutResourse, parent, false);
        NewCartFragmentViewHolder newCartCardViewHolder = new NewCartFragmentViewHolder(itemView);
        return newCartCardViewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        NewCartFragmentViewHolder cardViewHolder=(NewCartFragmentViewHolder) holder;
        ShowCartBean showCartBean=items.get(position);
        final String mrname=showCartBean.getMrname();

        cardViewHolder.nct_name.setText(mrname);
        final String pic=showCartBean.getPic();
        final String mrid=showCartBean.getMrid();
        Toast.makeText(context, mrname, Toast.LENGTH_SHORT).show();

        Picasso.with(context).load(items.get(position).getPic()).into(cardViewHolder.nct_img);

        cardViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CartFoodsActivity.class);
                intent.putExtra("mrid",mrid);
                context.startActivity(intent);
            }
        });
    }
}
